package cn.joeg.springbootrabbitmq.cofnig;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Joeg
 * @email 840459673@qq.com
 * @date 2019/7/19
 */

@Configuration
public class RabbitmqConfig {

    // 两个交换机
    @Bean("topicExchange")
    public TopicExchange getTopicExchange() {
        return new TopicExchange("TOPIC_EXCHANGE");
    }

//    // 两个交换机
//    @Bean("fanoutExchange")
//    public FanoutExchange getFanOutExchange() {
//        return new FanoutExchange("FANOUT_EXCHANGE");
//    }
//    // 三个队列


    @Bean("firstQueue")
    public Queue getFirstQueue() {
        Map<String, Object> args = new HashMap<String, Object>();
        args.put("x-message-ttl", 6000);
        Queue queue = new Queue("FIRST_QUEUE", false, false, false, args);
        return queue;
    }
//
//    @Bean("secondQueue")
//    public Queue getSecondQueue() {
//        return new Queue("SECOND_QUEUE", false, false, true, null);
//    }
//
//
//
//    @Bean("thirdQueue")
//    public Queue getThirdQueue() {
//        return new Queue("THIRD_QUEUE", false, false, true, null);
//    }



    //bind

    /**
     * FIXME
     * @param queue
     * @param exchange
     * @return
     */
    @Bean
    public Binding binFirst(@Qualifier("firstQueue") Queue queue, @Qualifier("topicExchange") TopicExchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with("#.gupao.#");
    }

//    //bind
//    // 两个绑定
//    @Bean
//    public Binding bindSecond(@Qualifier("secondQueue") Queue queue, @Qualifier("topicExchange") TopicExchange exchange){
//        return BindingBuilder.bind(queue).to(exchange).with("#.gupao.#");
//    }
//
//    @Bean
//    public Binding bindThird(@Qualifier("thirdQueue") Queue queue,@Qualifier("fanoutExchange") FanoutExchange exchange){
//        return BindingBuilder.bind(queue).to(exchange);
//    }

}
